<html>
  <head></head>
  <body>
    <div>
      <span>f</span>
      <span>o</span>
      <span>o</span>
    </div>
  </body>
  <script>
/* function walk(node,totalElementsCount=-1){
  node= Array.from(node);
  totalElementsCount+=node.length;
  if(node.length===0){
    return totalElementsCount;
  }
  let nextNode= [];
  node.map((item)=>{
    nextNode = item.children;
    totalElementsCount= walk(nextNode,totalElementsCount)
  })
  return totalElementsCount
}
console.log(walk(document.getElementsByTagName('html'))); */
/* const getIntersection = (...args) => {
            return args.reduce((item1, item2) => {
                if (!item1 || !item2) return null
                const a = Math.min(item1[0], item1[1])
                const b = Math.max(item1[0], item1[1])
                const c = Math.min(item2[0], item2[1])
                const d = Math.max(item2[0], item2[1])
                const e = Math.max(a, c)
                const f = Math.min(b, d)
                if (e <= f ) return [e,f]
                return null
            })
        } */

        function getIntersection(...args){
    let argsStart=[];
    let argsEnd=[];
    args.map((item)=>{
        const itemStr=`${item}`;
        const list=itemStr.split(',')
        let itemStart=parseInt(list[0]);
        let itemEnd = parseInt(list[1]);
        if(itemStart>itemEnd){
            itemStart=itemStart+itemEnd;
            itemEnd=itemStart-itemEnd;
            itemStart=itemStart-itemEnd
        }
        argsStart.push(itemStart);
        argsEnd.push(itemEnd);
    })
    argsStart=argsStart.sort();
    
    argsEnd=argsEnd.sort();
    let maxArgsStart=argsStart[argsStart.length-1]
    let minArgsEnd=argsEnd[0];
    let result=[];
    if(maxArgsStart<minArgsEnd){
        result.push(maxArgsStart)
        result.push(minArgsEnd)
    }
    if(result.length>1){
        return result;
    }
    return null;
 }
 console.log(getIntersection([2 ,5], [4, 9]));
 function statistics (root) {
    let totalElementsCount = -2;
    let maxDOMTreeDepth = 0;
    let maxChildrenCount = 0;
    let stack=[root];
    let nextStatck=[];
    while(stack.length||nextStatck.length){
        if(!stack.length){
            stack=nextStatck;
            nextStatck=[];
            maxDOMTreeDepth++;
        }
        let ele=stack.pop();
        totalElementsCount++;
        if(maxChildrenCount<ele.children.length){
            maxChildrenCount = ele.children.length;
        }
        nextStatck.push(...ele.children)
    }
    return {
        totalElementsCount,
        maxDOMTreeDepth,
        maxChildrenCount,
    }
}
console.log(statistics(document));
</script>
</html>

